#include "app_data.h"

void seriall_begin()
{
      Serial2.begin(250000, SERIAL_8N1, RXD, TXD);
}

uint8_t kb_data()
{
      if (Serial2.available() > 0)
      {
            String uart_read = "";
            while (Serial2.available() > 0)
                  uart_read += char(Serial2.read());
            if (uart_read.startsWith("KBRD") and uart_read.endsWith("FULL") and uart_read.length() == 11) // 判断开头类型
            {
                  uart_read.remove(0, 4);
                  uart_read.remove(3);
                  return uart_read.toInt();
            }
            else if (uart_read.startsWith("TM20") and uart_read.endsWith("FULL") and uart_read.length() == 14)
            {
                  uart_read.remove(0, 4);
                  uart_read.remove(6);
                  Serial.print(uart_read);
            }
            return 255;
      }
      else
      {
            return 0;
      }
}

void Serial2print(String key, String txdata)
{
      Serial2.printf("%s%s", key, txdata);
}